# encoding=UTF-8
import json

from DB_Helper import *
from Redis_Driver import *
from constant import datais

from live_api.tools.Third_Netease_ServerAPI import ServerAPI
AppKey = datais.AppKey
AppSecret = datais.AppSecret
##p = ServerAPI(AppKey,AppSecret);
p = ServerAPI(AppKey,AppSecret, UseSSLLib = True);

class ReturnJ(object):
    def __init__(self):
        #由于存在setattr,此处必须采用这种方式赋值
        self.__dict__['res'] = {
            'code': 200,
            'msg': '请求成功!'
        }

    def toJson(self):
        return json.dumps(self.res, ensure_ascii=False)

    def __setattr__(self, key, val):
            self.res[key] = val

if __name__ == "__main__":
    n, rows = db.query("select * from gift")
    res = ReturnJ()
    print res.toJson()
    res.code = 100
    res.msg = "out of range error"
    res.gift = rows

    print res.toJson()
